package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Collect;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.CollectMapper;
import cn.wolfcode.trip.base.query.CollectQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ICollectService;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CollectServiceImpl implements ICollectService {
    @Autowired
    private CollectMapper collectMapper;

    public int updateByCollectId(Collect collect) {
        return collectMapper.updateByPrimaryKey(collect);
    }

    public PageInfo queryForList(CollectQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        if (qo.getType() == 1) {
            List<Collect> strategiesList = collectMapper.selectForStrategies(qo);
            return new PageInfo(strategiesList);
        }else if (qo.getType() == 2) {
            List<Collect> travelsList = collectMapper.selectForTravels(qo);
            return new PageInfo(travelsList);
        }else{
            List<Collect> dailiesList = collectMapper.selectForDailies(qo);
            return new PageInfo(dailiesList);
        }
    }

    public Boolean queryfortravel(CollectQueryObject qo) {
        Collect collect = collectMapper.selectfortravel(qo);
        if(collect != null){
            return true;
        }else{
            return false;
        }
    }

    public void delete(CollectQueryObject qo) {
        collectMapper.deleteByPrimaryKey(qo);
    }

    public void save(CollectQueryObject qo) {
        User user = UserContext.getUser();
        qo.setUserId(user.getId());
        collectMapper.insert(qo);
    }

    public int queryforCount(CollectQueryObject qo) {
        return collectMapper.selectforCount(qo);
    }


}
